// pages/ScenicArea/MyCenter/index.js
const utils = require('../utils.js')
const common = require('../../../public.js')
const config = require('../../../config')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isFyApp: config.isFyApp,
    active: 4,
    userInfo: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  onShow() {
    const that = this
    common.getLocalUserInfo(function (success, data) {
      if (success) {
        that.setData({
          userInfo: data.user,
          token: data.token
        }, function () {
          // that.getActList();
          // that.getCode()
        })
      } else {
        that.setData({
          userInfo: null,
          token: '',
        })
      }
    })
  },

  toLogin() { // 去登陆
    common.showLoginPage()
  },

  onChangeTabbar(e) { //切换底部导航
    const index = e.detail.index
    const url = e.detail.url
    if (index != this.data.active) {
      utils.onChangeTabbar(url, this.data.storeId, this.data.moduleType)
    }
  },
  clickOrder(e) {
    const index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: '/pages/ScenicArea/ScenicAreaOrder/index?status=' + index,
    })
  },
  toGoodsOrder() {
    wx.navigateTo({
      url: '/packageA/pages/Goods/goodsOrder/goodsOrderList/index',
    })
  },
  toAddressManager() {
    wx.navigateTo({
      url: '/packageA/pages/Goods/Address/list/index?from=mySelf',
    })
  },
  /**
   * 跳转页面，该接口会验证用户是否登录
   * @param {string} url 跳转连接
   */
  checkLoginToJump(url) {
    if (!this.data.userInfo) {
      common.showToast('您尚未登录，请登录后再查看吧~')
    } else {
      wx.navigateTo({
        url
      })
    }
  },
})